package com.sunny.cloudgateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * gateway注册到注册中心后，调用其他服务的方式变更为：
 *  http://网关地址:端口/服务名称/方法路径
 *  例：http://127.0.0.1:9800/CLOUD-EUREKA-CLIENT/hi?name=123
 */
@SpringBootApplication
@RestController
public class CloudGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(CloudGatewayApplication.class, args);
    }

    /*@Bean
    public RouteLocator myRoute(RouteLocatorBuilder builder) {
        //当请求127.0.0.1:9800/get，会在请求头列表中增加一个Hello请求头，然后跳转到httpbin.org/get地址
        String httpUri = "http://httpbin.org:80";
        return builder.routes()
                        .route(r -> r.path("/get")
                                    .filters(f -> f.addRequestHeader("Hello", "world"))
                                    .uri(httpUri))
                                    .build();
    }*/


}
